#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Termstructures/Yield/RateHelper.h>
#pragma unmanaged 
#include <ql\termstructures\yield\ratehelpers.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Yield {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IFuturesRateHelper
	public ref class CFuturesRateHelper  : 
            public CRateHelper,
            public Cephei::QL::Termstructures::Yield::IFuturesRateHelper
	{
	protected: 
		boost::shared_ptr<QuantLib::FuturesRateHelper>* _ppFuturesRateHelper;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FuturesRateHelper>* _phFuturesRateHelper;
#endif
		Object^ _FuturesRateHelperOwner;     // reference to object that manages the storage for this object
	internal:
		CFuturesRateHelper (Double price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment);
		CFuturesRateHelper (Cephei::QL::IQuote^ price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment);
		CFuturesRateHelper (Double price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment);
		CFuturesRateHelper (Cephei::QL::IQuote^ price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment);
		CFuturesRateHelper (Double price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment);
		CFuturesRateHelper (Cephei::QL::IQuote^ price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment);
        CFuturesRateHelper (boost::shared_ptr<QuantLib::FuturesRateHelper>& childNative, Object^ owner);
        CFuturesRateHelper (QuantLib::FuturesRateHelper& childNative, Object^ owner);
        CFuturesRateHelper (CFuturesRateHelper^ copy);
        CFuturesRateHelper (PLATFORM::Type^ t);
#ifdef STRUCT
        CFuturesRateHelper (QuantLib::FuturesRateHelper childNative);
#endif       
#ifdef HANDLE
		CFuturesRateHelper (QuantLib::Handle<QuantLib::FuturesRateHelper>& childNative, Object^ owner);
		CFuturesRateHelper (QuantLib::Handle<QuantLib::FuturesRateHelper> childNative);
#endif
		virtual ~CFuturesRateHelper ();
		!CFuturesRateHelper ();

	internal:
		QuantLib::FuturesRateHelper& GetReference ();
		boost::shared_ptr<QuantLib::FuturesRateHelper>& GetShared ();
		QuantLib::FuturesRateHelper* GetPointer ();
        void SetFuturesRateHelper (boost::shared_ptr<QuantLib::FuturesRateHelper> native)
        {
            if (_ppFuturesRateHelper != NULL)
                delete _ppFuturesRateHelper;
            _ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (native);
            SetRateHelper (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FuturesRateHelper>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Double ConvexityAdjustment 
        {
		    virtual Double get () ;
        }
        property Double ImpliedQuote 
        {
		    virtual Double get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Termstructures::Yield::IFuturesRateHelper^>::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Yield::IFuturesRateHelper::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Yield::IFuturesRateHelper_Factory::typeid)]
	public ref class CFuturesRateHelper_Factory sealed : public IFuturesRateHelper_Factory
	{
	public:
        virtual IFuturesRateHelper^ Create (Double price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment);
        virtual IFuturesRateHelper^ Create (Cephei::QL::IQuote^ price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment);
        virtual IFuturesRateHelper^ Create (Double price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment);
        virtual IFuturesRateHelper^ Create (Cephei::QL::IQuote^ price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment);
        virtual IFuturesRateHelper^ Create (Double price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment);
        virtual IFuturesRateHelper^ Create (Cephei::QL::IQuote^ price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Yield */}
